package com.sky.es.dto;

import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;

import java.io.IOException;

public class Mapping {

    public static XContentBuilder getMapping(){
        XContentBuilder builder = null;
        try {
            builder = XContentFactory.jsonBuilder()
                    .startObject()//
                        .field("dynamic", "true")

                    .startObject("properties")
                    .startObject("id")
                        .field("type", "integer")
                        .field("store", "true")
                        .endObject()
                    .startObject("name")
                        .field("type", "keyword")
                        .endObject()
                    .startObject("age")
                        .field("type", "integer")
                        .field("store", "true")
                        .endObject()
                    .startObject("salary")
                        .field("type", "integer")
                        .field("store", "true")
                        .endObject()
                    .startObject("team")
                        .field("type", "keyword")
                        .endObject()
                    .startObject("position")
                        .field("type", "keyword")
                        .endObject()
                    .startObject("description")
                        .field("type", "text")
                        .field("store", "false")
                        .field("index", "true")
                        .field("analyzer", "ik_max_word")
                        .endObject()
                    .startObject("addr")
                        .field("type", "keyword")
                        .endObject()
                    .endObject()
                    .endObject();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return builder;
    }
}
